package com.hand.wyc24548.api.controller.v1;

import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hand.wyc24548.config.SwaggerApiConfig;
import com.hand.wyc24548.domain.entity.Customer;
import com.hand.wyc24548.domain.repository.CustomerRepository;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Author wangyc
 * @create 2019/8/8 20:26
 */

@Api(tags = SwaggerApiConfig.CUSTOMER)
@RestController("customer.v1")
@RequestMapping("/v1/customer")
public class CustomerController extends BaseController {
    private final CustomerRepository customerRepository;

    public CustomerController(CustomerRepository customerRepository) {
        this.customerRepository = customerRepository;
    }

    @Permission(level = ResourceLevel.ORGANIZATION)
    @ApiOperation(value = "分页查询客户信息")
    @GetMapping
    public ResponseEntity<Page<Customer>> pageTask(Customer customer, PageRequest pageRequest){
        return Results.success(customerRepository.pageAndSort(pageRequest,customer));
    }

}
